<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="app" uri="/application" %>
<%@ taglib  prefix="s"  uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="/css/css.css" rel="stylesheet" type="text/css" />
<link href="/css/role.css" rel="stylesheet" type="text/css" />
<style type="text/css">
html,body{ width:100%; font-size:12px; line-height:18px;overflow:hidden;background: #fff;}

.ul_tab li{float:left;display:block;padding:0 5px;heigth:30px;line-height: 30px;font-weight: bold;cursor:pointer;}
.ul_tab li.current{background: #fff;border-left:1px solid #666;border-right:1px solid #666;border-top:1px solid #666;color:#A2B5CD}
#file_div{}
#file_div ul li {display:block;border:1px dashed #ccc;margin:3px 6px;padding:1px;width:180px;height:60px;float:left;text-align: center;cursor: pointer;}
#file_div ul li img {height:50px;width:40px;margin:5px 2px;}
#file_div ul li.current{background:#eee;}

#file_div ul li div {color:#666;display:block;overflow: hidden;line-height:20px;text-align: left;float:right;width:136px;padding:5px 0; }
.table_1 td {border:1px solid #ccc;}

DIV.scott {
	PADDING-RIGHT: 3px;
	PADDING-LEFT: 3px;
	PADDING-BOTTOM: 3px;
	MARGIN: 3px;
	*MARGIN:0px;
	PADDING-TOP: 3px;
	TEXT-ALIGN: center;
	
}
DIV.scott A {
	BORDER-RIGHT: #ddd 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #ddd 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #ddd 1px solid; COLOR: #666; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #ddd 1px solid; TEXT-DECORATION: none
}
DIV.scott A:hover {
	BORDER-RIGHT: #826d56 1px solid;
	BORDER-TOP: #826d56 1px solid;
	BORDER-LEFT: #826d56 1px solid;
	COLOR: #999;
	BORDER-BOTTOM: #826d56 1px solid;
	BACKGROUND-COLOR: #D5D5D5
}
DIV.scott A:active {
	BORDER-RIGHT: #826d56 1px solid;
	BORDER-TOP: #826d56 1px solid;
	BORDER-LEFT: #826d56 1px solid;
	COLOR: #666;
	BORDER-BOTTOM: #826d56 1px solid;
	BACKGROUND-COLOR: #D5D5D5
}
DIV.scott SPAN.current {
	BORDER-RIGHT: #826d56 1px solid;
	PADDING-RIGHT: 5px;
	BORDER-TOP: #826d56 1px solid;
	PADDING-LEFT: 5px;
	FONT-WEIGHT: bold;
	PADDING-BOTTOM: 2px;
	BORDER-LEFT: #826d56 1px solid;
	COLOR: #fff;
	MARGIN-RIGHT: 2px;
	PADDING-TOP: 2px;
	BORDER-BOTTOM: #826d56 1px solid;
	BACKGROUND-COLOR: #666
}
DIV.scott SPAN.disabled {
	BORDER-RIGHT: #f3f3f3 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #f3f3f3 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #f3f3f3 1px solid; COLOR: #ccc; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #f3f3f3 1px solid
}
</style>
</head>
<body>
<div style="height:100%; width:100%;">
<div class="right_title" style="padding-left:50px;">
<ul class="ul_tab">
  <li class="current" id="ul_li_0" onclick="ck(this)">文件上传</li>
  <li id="ul_li_1" onclick="ck(this);WBR.sr();">选择已上传文件</li>  
</ul>
</div>
<div style="clear: both"/>
<div  id="tab_div_0">
<form action="/resource/saveResource.shtml" name="frm" method="post" enctype="multipart/form-data">
	<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">  
		<tr>
		  <td colspan="2">&nbsp;</td>
		</tr>
		<tr>
		  <td width="120" align="right">选择文件：</td>
		  <td><input name="resource" value="" id="resource_file" type="file"/> <input type="button" class="input01"  value="确定上传" onclick="_sm(this);"></td>
		</tr>
		<tr>
		  <td align="right">&nbsp;</td>
		  <td >&nbsp;<span style="color:red;"><s:fielderror><s:param>uploadError</s:param></s:fielderror></span></td>
		</tr>
	</table>
</form>
</div>

<div  style="display:none;" id="tab_div_1">
		<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%" class="table_1">  
		<tr>
			<td width="140" rowspan="3" valign="top"> 
				<div id="menupag">
		        <div class="menupag01">
		        	<div class="menu01" id="background_hegh">
		            	<h2>文档类型</h2>
		                <div class="menu01_title" id="menu01_title">
		                    <c:forEach items="${list}" var="o">
		                      <a id="${o[0]}" href="javascript:WBR.sr('${o[0]}');">${o[1]}</a>
		                    </c:forEach>
		                </div>
		            </div>
		            
		            <!--            <div class="menu01" id="background_hegh">
		            	<h2>预览选择</h2>
		                <div class="menu01_title" style="margin:0 auto;text-align: center;" >
		                    <div id="prewDiv" style="border:1px solid #ccc;margin:5px;height:120px;">
		                       
		                    </div>
		                    <input type="button" class="input01" onclick="WBR.hide();" value="确定选择" />
		                    <input type="hidden" value="" id="file_path"/>
		                    <div style="text-align: left;margin-left:5px;" id="file_name"></div>
		                </div>
		            </div>  -->
		
		        </div>
		    </div>
			</td>
			<td>
				<div style="height:28px;line-height: 28px;">&nbsp;文件关键字：<input type="text" id="fileName_filter"  name=""> <input value="查询" type="button" onclick="WBR.sr();"/></div>
			</td>
		
		</tr>
		<tr>
			<td>
				<div id="file_div" style="height:315px; overflow: auto;">
				    
				</div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="page_foot" class="scott">&nbsp;
				</div>
			</td>
		</tr>
		</table>
</div>

</div>
<div id="wait_div" style="height:60px;line-height: 30px;display:none;">
    <img src="/images/wait.gif" /><br/>
   &nbsp;文件正在上传中，请稍等片刻...
</div>
</body>
</html>
<script src="/scripts/util.js" type="text/javascript"></script>
<script src="/scripts/xhr.js" type="text/javascript"></script>
<script src="/scripts/page_list.js" type="text/javascript"></script>

<script src="/scripts/form_validate.js" type="text/javascript"></script>
<script type="text/javascript">
    var filepath = '${path}';
    function ck(th){
       var i=0;var li;
       while(li=util.$('ul_li_'+i)){
          li&&(li.setAttribute('class',''));
          i++;
       }
       th.setAttribute('class','current');
       
       var n=0;var div;
       var s = util.childNum(th);
       while(div=util.$('tab_div_'+n)){
         div.style.display=n==s?'':'none';
         n++;
       }
    }
    
    
    
     validate.addvalidte(document.frm,{
        rules:{
           resource:{checkNull:true,event:"change"},
           },
	    message:{
	       resource:{checkNull:"请选择",suffix:""},
	    }
	    });
   function _sm(th){
       if(validate.getSubmit()()){
	       if(confirm('确定上传?')){
			   document.frm.submit();
		       util.dusk_div("wait_div");
		    }
       }
   }
   
   var WBR=(function(){
      var type='${type}';var file_div = util.$('file_div');
      var prewDiv=util.$('prewDiv');
      var file_path = util.$('file_path');
      var file_name = util.$('file_name');
      var cache={};
      var img_server='';
      return {
          init:function(){
             if(filepath.length!=0){
               WBR.hide(filepath);
             }else{
	             try{
	               var file = util.$('resource_file');
	               //file.click();
		             /**
		             if(broswer.isIE){
		                file.click();
		             }else if(broswer.isMozilla){
		                var a=document.createEvent("MouseEvents");
		                a.initEvent("click", true, true); 
		                file.dispatchEvent(a);
		             }*/
	             }catch(e){}
             }
             
          },
          sr:function(t){
             type=t||type;
             if(cache[""+type+""]){
                 var o = cache[""+type+""];
                 WBR.fill(o);
             }else{
                 function cb(d){
	                //var o = eval("("+d+")");
	                //cache[""+type+""]=d;
	                WBR.fill(d.list);
	                
	             }
	             var val = util.$('fileName_filter').value;
	             var page = new Page('/resource/searchResource,'+type+".shtml",cb,util.$('page_foot'));
	             page.setPageSize(30);
	             if(val.length!=0){
	                page.setParameter('resName',val);
	             }
	             page.execute();
	             
	             
	             //new xhr('/resource/searchResource,'+type+".shtml",cb).execute();
             }
          },
          cur:function(){
            util.each(util.$('menu01_title').getElementsByTagName('a'),function(e){
               e.setAttribute("class",(e.id==type)?'cur':'');
             //  e.className=(e.id==type)?'cur':'';
            })
            
          },
          fill:function(d){
             var val = util.$('fileName_filter').value;
             var reg = new RegExp("^.*"+val+".*$");
             var _html='<ul id="file_list_ul">';
             if(d.length==0){
             _html+='<li style="padding:1px;color:#FF6666;;border:none;"> 无匹配文件...</li>';
             }else{
                 util.each(d,function(e){
	                //_html+='<li style="padding:1px;"> <a href="javascript:WBR.prew(\''+e.resPath+'\',\''+e.resName+'\',\''+e.resType+'\');" style="height:20px;line-height:20px;font-size:16px;">'+e.resPath+' </a> <span style="color:#666;">'+e.resName+'('+e.createDate+')</span></li>';
	               (e.resName.match(reg))&&(_html+='<li style="padding:1px;" onclick="WBR.check(this);" ondblclick="javascript:WBR.hide(\''+e.resPath+'\');" title="'+e.resName+'"><img src="'+WBR.getPath(e.resPath,e.resName,e.resType)+'"   /><div >'+util.substring(e.resName,10).replace(val,('<b style="color:#ff6666;">'+val+'</b>'))+'<br/>大小:'+e.resSpace+'k&nbsp;类型:'+e.suffix+'</div></li>');
	             });
             }
             _html+='</ul>';
             file_div.innerHTML=_html;
             WBR.cur();
          },
          check:function(th){
             var ul = util.$('file_list_ul');
             document;
             util.each(ul.getElementsByTagName('li'),function(e){e.className=''});
             th.className='current';
          },
          prew:function(p,n,t){
             var pew='';
             //var img_server='http://192.168.50.206';
             switch(t){
               case 'IMG':
                 pew=img_server+p;
                 break;
               case 'MUSIC':
                 pew='/images/employee.gif';
                 break;
               case 'VIEW':
                 pew='/images/view.jpg';
                 break;
               case 'MTEXT':
                 pew='/images/employee.gif'; 
                 break;
               case 'DOC':
                 pew='/images/employee.gif';
                 break;
               default:
                 pew='/images/employee.gif'
             }
             prewDiv.innerHTML='<img style="width:100%;height:100%;" src="'+pew+'" />';
             file_path.value=p;
             file_name.innerHTML='选择文件<br/>'+n;
          },
          getPath:function(p,n,t){
             var pew='';
             switch(t){
               case 'IMG':
                 pew=img_server+p;
                 break;
               case 'MUSIC':
                 pew='/images/music.jpg';
                 break;
               case 'VIEW':
                 pew='/images/view.jpg';
                 break;
               case 'MTEXT':
                 pew='/images/mtext.jpg'; 
                 break;
               case 'DOC':
                 pew='/images/doc.jpg';
                 break;
               default:
                 pew='/images/def.jpg'
             }
             return pew;
          },
          hide:function(v){
             //var v = file_path.value;
             if(v.length==0){
               alert('请选择文件...');
             }else{
               window.parent&&window.parent.HOME.parent_hide(v);
             }
          }
      }
   })();
   WBR.init();

</script>
